<?php
/*
 * @Author: CHINAKAIYUAN<sunkaiyuan@namenode.cn>
 * @Date: 2022-02-03 00:33:05
 * @LastEditTime: 2022-08-25 21:33:51
 * @LastEditors: CHINAKAIYUAN
 * @Description: 
 */

namespace App\Models;

use App\Traits\AutoCodeTrait;
use App\Traits\MaterialTrait;

class OpenCard extends BaseModel
    {
    use AutoCodeTrait;
    use MaterialTrait;
    public $timestamps = true;
    public $table = "sys_open_card";
    protected $guarded = [];
    public $ACSign = "OPEN_CARD";

    public function details()
        {
        return $this->hasMany(OpenCardDetails::class, "main_id");
        }

    public function craft_history()
        {
        return $this->hasMany(OpenCardCraftHistory::class, "open_card_id");
        }
    public function shell_fabric()
        {
        return $this->hasMany(OpenCardShellFabric::class, "open_card_code", "code");
        }
    public function ground_fabric()
        {
        return $this->hasMany(OpenCardGroundFabric::class, "open_card_code", "code");
        }
    public function bom()
        {
        return $this->belongsTo(ProBom::class);
        }
    public function glue()
        {
        return $this->hasMany(OpenCardGlue::class, "open_card_code", "code");
        }
    public function raws()
        {
        return $this->hasMany(OpenCardRaws::class, "main_id");
        }

    public function process_route()
        {
        return $this->belongsTo(ProProcessRoute::class);
        }
    public function linkman()
        {
        return $this->belongsTo(CompanyLinkMan::class);
        }
    public function status()
        {
        return $this->belongsTo(Dic::class, "status_id", "key")->where(function ($q)
            {
            $q->where("code", 'status_name');
            });
        }
  
    }
